package com.czb.server.controller;


import com.czb.server.pojo.RespBean;
import com.czb.server.pojo.Salary;
import com.czb.server.service.ISalaryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhanglishen
 * @since 2022-02-20
 */
@RestController
@RequestMapping("/salary/sob")
public class SalaryController {

    @Autowired
    private ISalaryService salaryService;

    @ApiOperation(value = "获取所有工资帐套")
    @GetMapping("/")
    public List<Salary> getAllSalaries() {
        return salaryService.list();
    }

    @ApiOperation(value = "添加员工帐套")
    @PostMapping("/")
    public RespBean addSalary(@RequestBody Salary salary) {
        return salaryService.save(salary) ? RespBean.success("添加成功") : RespBean.error("添加失败");
    }

    @ApiOperation(value = "删除员工帐套")
    @DeleteMapping("/{id}")
    public RespBean deleteSalary(@PathVariable Integer id) {
        return salaryService.removeById(id) ? RespBean.success("删除成功") : RespBean.error("删除失败");
    }
    @ApiOperation(value = "修改员工帐套")
    @PutMapping("/")
    public RespBean updateSalary(@RequestBody Salary salary) {
        return salaryService.updateById(salary) ? RespBean.success("修改成功") : RespBean.error("修改失败");
    }
}
